package sui.utils.excel;

import com.alibaba.fastjson.JSON;

import java.io.File;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @Description 读取Excel数据
 * @Author XQF.Sui
 * @Date 2020/3/18 7:35 下午
 * @Version 1.0
 */
public class ReaderExcelData {

    private static final String dicPath = "/Users/suigaopeng/Downloads/股权类产品投资者名录";

    public static void main(String[] args) throws ExcelException {
        File file = new File(dicPath);

        lodDicFiles(file);
    }

    private static void lodDicFiles(File dic) throws ExcelException {

        if (dic == null) {
            System.out.println("路径不能为空");
            return;
        }

        if (!dic.isDirectory()) {
            System.out.println("不是目录");
            return;
        }

        File[] files = dic.listFiles();

        if (files == null || files.length == 0) {
            System.out.println("目录下无文件");
            return;
        }

        Set<String> set = new HashSet<>();

        for (File file : files) {
            ExcelUtils excel = ExcelUtils.loadExcelFile(file);

            System.out.println("file name:" + file.getName());

            List<EcifEntity> list = excel.excelToList(0, EcifEntity.class);

            for (EcifEntity ecif : list) {
                set.add(ecif.getECIFID());
            }
        }

        System.out.println("ECIFID: " + JSON.toJSONString(set));
    }
}

class EcifEntity {

    private String ECIFID;

    public String getECIFID() {
        return ECIFID;
    }

    public void setECIFID(String ECIFID) {
        this.ECIFID = ECIFID;
    }
}